@layout("/common/_curd/_container.html"){

<script type="text/javascript">
	var ctx = "${basePath}";
	var grid_selector = "#grid-table";
	var pager_selector = "#grid-pager";
	var dept  = ${deptid};
	var role = ${role};
	console.log(role)
	var mys = 0;
	if(role==8){
		mys = 104;
	}else if(role == 9){
		mys = 103;
	}else if(role == 10){
		mys = 102;
	}else if(role == 11){
		mys = 101;
	}

	$(function(){
		initGrid();
		initMenuBtn("btns", "${code}");
	});

	function initGrid(){
		var grid_url = ctx + "/${code}/list";
		var _colnames = ["",
			"操作员",
//			"分公司",
			"申请部门",
			"付款方式",
			"付款金额",
			"收款单位",
			"开户银行",
			"帐号",
			"申请日期",
			"状态ID",
			"状态",
			"备注",
			"操作"
		];
		var _colmodel = [{name:"id", index:"id",hidden:true, width:100},
			{name:"uname", index:"uname", width:100},
//			{name:"company_id", index:"company_id", width:100},
			{name:"dname", index:"dname", width:100},
			{name:"pay_type", index:"pay_type", width:100},
			{name:"totle_price", index:"totle_price", width:100},
			{name:"pay_to", index:"pay_to", width:100},
			{name:"bank", index:"bank", width:100},
			{name:"bank_account", index:"bank_account", width:100},
			{name:"apply_date", index:"apply_date", width:100,formatter:function (value, rows, index) {
			if(value !== ""){
				return value.substring(0,10);
			}}},
			{name:"status", index:"status",hidden:true, width:100},
			{name:"staname", index:"staname", width:100},
			{name:"remarks", index:"remarks", width:100},
			{name:"remarks", index:"remarks", width:200,formatter:function (value, rows, index) {
				var status =  index.status;
				var orderId = index.id;
				var role = '${role}';
				var html = "";
				var shhtml = ""
				shhtml += '<a class="btn  btn-success btn-xs" href="#" role="button" onclick="passShowInput('+orderId+","+status+')">审核通过</a>';
				shhtml += '<a class="btn btn-warning btn-xs" href="#" role="button" onclick="backShowInput('+orderId+","+200+')">审核不通过</a>';
//				shhtml += '<a class="btn btn-danger btn-xs" href="#" role="button" onclick="backFirst('+orderId+')">退回修改</a>';
				if(role == 1 ){//超级管理员
					html = html + shhtml;
				}else if(role == 8){
					if(status==104){
						html = html + shhtml;
					}
				}else if(role == 9){
					if(status == 103){
						html = html + shhtml;
					}
				}else if(role == 10){
					if(status == 102){
						html = html + shhtml;
					}
				}else if(role == 11){
					if(status == 101){
						html = html + shhtml;
					}
				}
				return html;
			}}
		];



		if(mys > 0){
			jQuery(grid_selector).jqGrid({
				url : grid_url,
				shrinkToFit : true,
				colNames : _colnames,
				colModel : _colmodel,
				jsonReader : {id :"id"},
				pager : pager_selector,
				postData : {sort : "id",
					where:"{dept:"+dept+",status:"+mys+"}",
					order : "desc"}
			});
		}else{
			jQuery(grid_selector).jqGrid({
				url : grid_url,
				shrinkToFit : true,
				colNames : _colnames,
				colModel : _colmodel,
				jsonReader : {id :"id"},
				pager : pager_selector,
				postData : {sort : "id",
					where:"{dept:"+dept+"}",
					order : "desc"}
			});
		}

	}
</script>


<!-- 配置 grid -->
<div class="row">
	<div class="col-xs-12 tb-grid">
		<!-- 配置 查询 -->
		@ var _col=[
		@		{name:"发布时间(大于)",index:"addtime_dategt", type:"date"},
		@		{name:"发布时间(小于)",index:"addtime_datelt", type:"date"}
		@];
		@ include("/common/_function/_search.html",{"col":_col}){}
		<!-- 按钮 -->
		<!--<div class="welljq well-sm" id="btns"></div>-->
		<div class="welljq well-sm" id="btnsss">
			<button class="btn btn-xs btn-white " id="snOrderPay_adds" onclick="_add()">
				&nbsp;<li class=" fa fa-floppy-o bigger-120"></li>
				&nbsp;新增&nbsp;
			</button>
			&nbsp;
			<button class="btn btn-xs btn-white " id="snOrderPay_edit">&nbsp;<li class=" fa fa-pencil  bigger-120">
			</li>&nbsp;修改&nbsp;</button>&nbsp;<button class="btn btn-xs btn-white " id="snOrderPay_view">&nbsp;
			<li class=" fa fa-eye bigger-120"></li>
			&nbsp;查看&nbsp;</button>&nbsp;
			<button class="btn btn-xs btn-white " id="snOrderPay_remove">&nbsp;
				<li class=" fa fa-times  bigger-120">
				</li>&nbsp;删除&nbsp;
			</button>&nbsp;

			<button class="btn btn-xs btn-white " id="no_pass" onclick="no_pass()">&nbsp;
				<li class="glyphicon glyphicon-time  bigger-120">
				</li>&nbsp;待审核&nbsp;
			</button>&nbsp;

			<button class="btn btn-xs btn-white " id="has_pass"  onclick="has_pass()">&nbsp;
				<li class=" glyphicon glyphicon-list-alt  bigger-120">
				</li>&nbsp;已审核&nbsp;
			</button>&nbsp;

			<button class="btn btn-xs btn-white " id="all_apply" onclick="all_apply()">&nbsp;
				<li class="glyphicon glyphicon-list  bigger-120">
				</li>&nbsp;所有申请&nbsp;
			</button>&nbsp;
		</div>
		<!-- grid -->
		<table id="grid-table"></table>
		<!-- 分页-->
		<div id="grid-pager"></div>
	</div>
</div>

<style>
	.option{
		display: none;
		position: fixed;
		top:30%;
		left:40%;
		width:300px;
		height: 300px;
		border:1px solid grey;
	}
	.op_head{
		height: 30px;
		background-color: #00b3ee;
		text-align: center;
		line-height: 30px;
	}
</style>

<div class="option">
	<div class="op_head">
		<span style="color: white">审核意见</span>
	</div>
	<textarea id="option" class="form-control" id="" cols="30" rows="8"></textarea>
	<input type="hidden" id="this_orderId" value="">
	<input type="hidden" id="this_status" value="">
	<div style="text-align: center;margin-top: 20px">
		<a class="btn  btn-default" href="#" role="button" onclick="pass()">确定</a>
		&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
		<a class="btn  btn-default" href="#" role="button" onclick="cancel()">取消</a>
	</div>
</div>
<script>

	var ss = "pass"
	var role = '${role}';
	var mystatus = 101;
	if(role==8){
		mystatus = 104;
	}else if(role == 9){
		mystatus = 103;
	}else if(role == 10){
		mystatus = 102;
	}else if(role == 11){
		mystatus = 101;
	}
	cancel = function(){
		$(".option").hide();
	}

	no_pass = function () {
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+mystatus+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");
	}

	has_pass = function () {
		var myHas = mystatus +1;
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+myHas+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");

	}

	all_apply = function () {
		$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{}",order : "desc" }, page: 1 }).trigger("reloadGrid");
	}


	passShowInput = function(orderId,status){
		if(status <105){
			status++;
		}
		$("#this_orderId").val(orderId);
		$("#this_status").val(status);
		$("#option").val("");
		$(".option").show();
		ss = "确定通过审核吗？";
	}

	backShowInput = function(orderId,status){
		ss = "确定退回申请吗？";
		if(status >100){
			status--;
		}
		$("#this_orderId").val(orderId);
		$("#this_status").val(status);
		$("#option").val("");
		$(".option").show();
	}

	backFirst = function(orderId){
		ss = "确定退回最初状态吗？";
		$("#this_orderId").val(orderId);
		$("#this_status").val(101);
		$("#option").val("");
		$(".option").show();
	}
	pass  = function(){
		var orderId =  $("#this_orderId").val();
		var status =  $("#this_status").val();
		var opstep = $("#option").val();
		layer.msg(ss, {
			time: 0 //不自动关闭
			,btn: ['确定','取消']
			,yes: function(){
				var ajaxData = {status:status,orderId:orderId}
				if(status == 102){
					ajaxData.opstep1 = opstep;
				}else if(status ==103) {
					ajaxData.opstep2 = opstep;
				}else if(status ==104) {
					ajaxData.opstep3 = opstep;
				}else if(status ==105) {
					ajaxData.opstep4 = opstep;
				}
				$.post("/snOrderPay/pass",ajaxData,function (res) {
					if(res["success"]){
						layer.msg("操作成功！", {shift: -1,time:500,end:function () {
							$(".option").hide()
							$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",where:"{status:"+mystatus+"}",order : "desc" }, page: 1 }).trigger("reloadGrid");
						}});
					}
				})

			}
		});

	}

	// back  = function(orderId,status){
	//     layer.msg('确定退回审核吗？', {
	//         time: 0 //不自动关闭
	//         ,btn: ['确定','取消']
	//         ,yes: function(){
	//             if(status > 1){
	//                 status--;
	//             }
	//             var ajaxData = {status:status,orderId:orderId}
	//             ajaxData.opstep1 = "HelloWorld"
	//             $.get("/snOrderPay/pass",ajaxData,function (res) {
	//                 if(res["success"]){
	//                     layer.msg("操作成功！", {shift: -1,time:500,end:function () {
	//                             $jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
	//                         }});
	//                 }
	//             })
	//
	//         }
	//     });
	//
	// }


	_add = function () {
		var index = layer.open({
			type: 2,
			title:'选择商品',
			area: ['100%', '100%'],
			maxmin:true,
			shadeClose: true, //点击遮罩关闭
			content:  '/snOrderPay/add',
			end:function () {
				$jqGrid.jqGrid("setGridParam", { postData: { sort : "id",order : "desc" }, page: 1 }).trigger("reloadGrid");
			}
		});

		this.layerIndex = index;
	}
</script>
<!-- 引入所需的js -->
@include("/common/_listscript.html"){}

@}